package com.eleadmin.common.system.controller;

import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.system.service.MedicalImagingService;
import com.eleadmin.common.system.entity.MedicalImaging;
import com.eleadmin.common.system.param.MedicalImagingParam;
import com.eleadmin.common.core.web.ApiResult;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.common.core.web.PageParam;
import com.eleadmin.common.core.web.BatchParam;
import com.eleadmin.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 医学图像信息表控制器
 *
 * @author EleAdmin
 * @since 2025-03-16 22:21:54
 */
@Api(tags = "医学图像信息表管理")
@RestController
@RequestMapping("/system/medicalImaging")
public class MedicalImagingController extends BaseController {
    @Resource
    private MedicalImagingService medicalImagingService;


    @OperationLog
    @ApiOperation("分页查询医学图像信息表")
    @GetMapping("/page")
    public ApiResult<PageResult<MedicalImaging>> page(MedicalImagingParam param) {

        return success(medicalImagingService.pageRel(param));

    }


    @OperationLog
    @ApiOperation("查询全部医学图像信息表")
    @GetMapping()
    public ApiResult<List<MedicalImaging>> list(MedicalImagingParam param) {
        PageParam<MedicalImaging, MedicalImagingParam> page = new PageParam<>(param);

        return success(medicalImagingService.list(page.getOrderWrapper()));

    }


    @OperationLog
    @ApiOperation("根据id查询医学图像信息表")
    @GetMapping("/{id}")
    public ApiResult<MedicalImaging> get(@PathVariable("id") Integer id) {
        return success(medicalImagingService.getById(id));

    }


    @OperationLog
    @ApiOperation("添加医学图像信息表")
    @PostMapping()
    public ApiResult<?> save(@RequestBody MedicalImaging medicalImaging) {
        //获取当前登录用户
        medicalImaging.setCreateUser(getLoginUser().getNickname());
        if (medicalImagingService.save(medicalImaging)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("修改医学图像信息表")
    @PutMapping()
    public ApiResult<?> update(@RequestBody MedicalImaging medicalImaging) {
        //获取当前登录用户
        medicalImaging.setCreateUser(getLoginUser().getNickname());
        if (medicalImagingService.updateById(medicalImaging)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("删除医学图像信息表")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (medicalImagingService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }


    @OperationLog
    @ApiOperation("批量添加医学图像信息表")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<MedicalImaging> list) {
        if (medicalImagingService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("批量修改医学图像信息表")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<MedicalImaging> batchParam) {
        if (batchParam.update(medicalImagingService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("批量删除医学图像信息表")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (medicalImagingService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
